package com.jsjvm.server.dbgproxy;

import java.io.IOException;
import java.io.OutputStream;

import com.jsjvm.server.dbgproxy.jdwp.data.JDWPOutputStream;
import com.jsjvm.shared.jdwp.events.JDWPEvent;

public class JDWPEventOutputStream  extends JDWPOutputStream {
	public static final int SUSPEND_NONE 	= 0;
	public static final int SUSPEND_THREAD 	= 1;
	public static final int SUSPEND_ALL 	= 2;
	
	public JDWPEventOutputStream(OutputStream out) {
		super(out);
	}

	// FIXME implement writeEvent (keep track of requests)
	public void writeEvent(JDWPEvent e) throws IOException {
		switch(e.getType()){
		case VM_START:
			appendInt(SUSPEND_ALL);
			appendInt(1);	// one event
			appendInt(0);	// generated
			appendInt(JDPABackEnd.THREAD_ID);
			break;	
		case CLASS_PREPARE:
		case BREAKPOINT:
		case EXCEPTION:
		case METHOD_ENTRY:
		case METHOD_EXIT:
		case METHOD_EXIT_WITH_RETURN_VALUE:
		case SINGLE_STEP:
		case VM_EXIT:
			System.out.println("Event:" + e.getType());
			break;
		default:
			System.out.println();
		}
		commitEventPacket();
	}

	public void writeEvents(JDWPEvent events[]) throws IOException{
		for (JDWPEvent e : events)
			writeEvent(e);
	}
	
}
